<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>重置密码</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="${ctx}/rs/js/jquery.validate.min.js"></script>
<script src="${ctx}/rs/js/jquery.form.js" type="text/javascript"></script>
</head>
<body>
  <form id="form1" class="form-horizontal" action="${ctx}/user/updatePwd.htm" method="post">
      <div class="form-group">
        <label for="name" class="col-sm-2 control-label item wid1">新密码：</label>
        <div class="col-sm-9 wid2">
          <input type="hidden" id="id" name="id" value="${id}"/>
          <input type="password" class="form-control itemput" id="pwd" name="pwd" />
          <span class="help-block" id="valierr" style="color:#FF9966">*</span>
        </div>
      </div>

	  <div class="form-group">
        <label for="name" class="col-sm-2 control-label item wid1">密码确认：</label>
        <div class="col-sm-9 wid2">
          <input type="password" class="form-control itemput" id="resetpwd" name="resetpwd" />
          <span class="help-block" id="valierr" style="color:#FF9966">*</span>
        </div>
      </div>
	  
      <div class="form-group">
        <div class="col-sm-10 text-center pt15">
		     <button type="button" class="btn btn-primary btn-lg srt-btn active mr30" onclick="valiSubmit()">提交</button>
		     <button type="button" class="btn btn-default btn-lg srt-btn active" onclick="onReset()">重置</button>
        </div>
      </div>
 <div class="form-group">
        <div class=" col-sm-10">
          <span id="error-text" style="color: #FF0000;"></span>
        </div>
      </div>
     
  </form>
  
  <script type="text/javascript" src="${ctx}/rs/js/bootstrapQ.min.js"></script>
  <script src="${ctx}/rs/js/messages_zh.min.js"></script>
  <script type="text/javascript">
  $.validator.addMethod("limitPwd", function(value, element) {
      return this.optional(element) || /^\S*$/.test(value);
  }, "不允许空格");
    
    //初始化验证 start
	var form = $('#form1');
    form.validate({
		rules : {
			pwd : {
				rangelength : [6,20],
				required : true,
				limitPwd : "limitPwd"
			},
			resetpwd : {
				equalTo : "#pwd",
				required : true
			}
		},
		messages : {
			pwd : {
				  rangelength : "请输入6~20个字符"
			}

		},
		highlight : function(element) {
			$(element).closest('.form-group').removeClass('success').addClass(
					'error');
		},
		success : function(element) {
			element.text('OK!').addClass('valid').closest('.form-group')
					.removeClass('error').addClass('success');
		}
	});
	/** end */

	function valiSubmit() {
		if (form.valid()) {
			var data = $("#form1").serialize(); //获取表单多个控件的数据
			$.ajax({
                url: "${ctx}/user/updatePwd.htm",
                type: "post",
                data: data,
                success: function (result) {
               	// 普通消息提示条
                	if(!$('.unable').is(':hidden')){
						$(".unable").hide();
					} 
                	bootstrapQ.msg({
						msg : '保存成功！',
						type : 'success',
						time : 2000
					});
					//触发隐藏确认的按钮，引用回调方法关闭窗口并刷新列表
					$("button.bsok").click();
			  },
			  error : function(result) {
					if(!$('.unable').is(':hidden')){
						$(".unable").hide();
					}
					bootstrapQ.msg({
						msg : '保存失败！',
						type : 'danger',
						time : 2000
					});
			  }
			  });
     	}
	}

	function onReset() {
		$("#pwd").val("");
		$("#resetpwd").val("");
	}
</script>

</body>
</html>